Example: Connecting Sources and Listeners |
![]() |
The ActionListener interface only defines one method
class PrintMessage implements ActionListener { public void actionPerformed(ActionEvent e){ System.out.println("Hello World"); } } |
![]() |
Buttons are ActionListener sources
Button b = new Button("Print Hello"); b.addActionListener(new PrintMessage()); |